// miniprogram/pages/profile-list/profile-list.js
const MAX_LIMIT = 10
const db = wx.cloud.database()
let type = 0
let setName = ''
var req = require("../../utils/action.js"),utils = require("../../utils/util.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemList: [],
    pageNo:1,
    pageSize:20
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    let userInfo = await getApp().globalData.userInfo
    this.setData({userInfo:userInfo})
    this._getItemList()
  },
  _getItemList() {
    let that = this,_url = req.actions.ym+ "zentoComment/getMyCommentList",
    params={
      customerId:getApp().globalData.userInfo.id,
      pageNo:that.data.pageNo,
      pageSize:that.data.pageSize
    }
    wx.showLoading({
      title: '加载中',
    })
    utils.getAction(params,_url,function(res){
      console.log("_getItemList:"+JSON.stringify(res))
      that.setData({
        itemList:that.data.itemList.concat(res.data.result.records)
      })
      wx.hideLoading({
        success: (res) => {},
      })
    })
  },
  viewInvitation: function(event) {
    wx.navigateTo({
      url: '../../pages/campus-comment/campus-comment?type=2&itemId='+event.currentTarget.dataset.id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},

  onReachBottom: function () {
    //this._getItemList(setName)
    this.setData({
      pageNo:this.data.pageNo+1
    })
    this._getItemList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  goComment(event) {
    console.log(event)
    let itemId = type == 0 ? event.currentTarget.dataset.item.itemId : event.currentTarget.dataset.item._id
    wx.navigateTo({
      url: '../../pages/campus-comment/campus-comment?itemId=' + itemId,
    })
  },
})